import link from "../../api/Link.js";
import apiUrl from "../../api/url.js";

const HomeModule: object = {
  state: {
    navBool: false,
    dialogFormVisible: false, // 控制模态框的显示和隐藏
    uplistData: {},
    listDate: [],
  },
  mutations: {
    SET_NAV_BOOL(state: any) {
      // console.log(state);
      state.navBool = !state.navBool;
    },
    // 修改模态框的状态,
    SET_DIALOG(state: any, payload: any) {
      state.dialogFormVisible = !state.dialogFormVisible;
      state.uplistData = payload;
    },
    // 修改模态框的状态
    DIALOG(state: any) {
      state.dialogFormVisible = !state.dialogFormVisible;
      window.location.reload(); // 页面自动刷新
    },
    LISTDATE(state: any, payload: any) {
      state.listDate = payload;
    },
  },
  actions: {
    USERUPDATE_LIST(context: any) {
      link(apiUrl.userlist).then((ok: any) => {
        context.commit("LISTDATE", ok.data);
      });
    },
    // 删除操作
    DEL_DATA(context: any, payload: any) {
      link(apiUrl.userlist + "/" + payload.id, "delete").then((ok: any) => {
        window.location.reload();
      });
    },
  },
  getters: {},
};
export default HomeModule;
